//
//  DudelView.m
//  iPadDev01
//
//  Created by smu on 11-7-28.
//  Copyright 2011年 duk. All rights reserved.
//

#import "DudelView.h"
#import "Drawable.h"

@implementation DudelView
@synthesize drawables;

//两个不同的初始方法，第一个通常会在代码中被调用
-(id)initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame])) {
        drawables = [[NSMutableArray alloc] initWithCapacity:100];
    }
    return self;
}
//第二个会在对象从nib文件被实例化时调用
- (id)initWithCoder:(NSCoder *)aDecoder
{
    if ((self = [super initWithCoder:aDecoder])) {
        drawables = [[NSMutableArray alloc] initWithCapacity:100];
    }
    return self;
}

//每当drawRect:被调用（这是因为有人从某地调用视图上的setNeedsDisplay）
//这个视图会调用draw方法
- (void)drawRect:(CGRect)rect
{
    for (<Drawable> d in drawables) {
        [d draw];
    }
    [delegate drawTemporary];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc
{
    [drawables release];
    [super dealloc];
}

@end
